/*
  Creator: Kisamin Resident and copyright by her.  All rights reserved except those specifically set forth here:
  You may:
  	Use these scripts in any project
	Modify these scripts in any way you wish subject to:
		1. Retaining this set of comments
		2. Explicity commenting and showing any changes you might make
	You may NOT:
	License these scripts to someone else with restrictions differing from the above.
	Charge a fee for the scripts themselves (although you may charge for an object that
		utilizes these scripts to add functionality)
	Charge a fee for any "library" or "collection" of scripts that includes this script.

If you have questions about your rights under this coment and/or the Gnu CopyLeft, please request further information
and/or explicit permission from Kisamin Resident
*/

vector k_vDamagePrimVelocity = <200., 0., 0.>;
integer k_iDamageAmount = 100;

integer g_iDamageCoreNumber;

integer	k_iNumDamagePrims = 5;

integer	k_iCmdAnnounce	= 10000;			// Command code for link messages
integer	k_iCmdExplode	= 10001;			// Tell the warhead to explode
integer k_iCmdNewTarget = 10002;			// We've locked on to a new victim
integer k_iCmdSelfDestruct = 10003;			// We need to self -destruct either due to time or some other function.
integer	k_iCmdKill = 11000;					// Tell a damage script to kill someone

list		g_kVictim;							// Who are we going to kill?

vector k_iRezOffset = <5.0001, 0., 0.>;		// Offset from the rezzer for us to create the killer

 default {
   state_entry() {
	 list l_lNameParts = llParseString2List (llGetScriptName (), [" "], []);
	 string l_sLastNamePart = llList2String (l_lNameParts, -1);
	 g_iDamageCoreNumber = (integer)l_sLastNamePart;
   }
   
   link_message (integer in_iFromPrim, integer in_iCommand, string in_sData, key in_kTarget) {
	 if ((in_iCommand < k_iCmdKill)
		 || (in_iCommand > k_iCmdKill + 999)
		 || (in_iCommand - k_iCmdKill != g_iDamageCoreNumber))
	   return;

	 g_kVictim += (string)in_kTarget;
	 
	 integer i;
	 for (i=0; i<k_iNumDamagePrims; i++) {
	   list l_lObjectDetails = llGetObjectDetails (g_kTarget, [OBJECT_POS]);
	   vector l_vTargetPos = llList2Vector (l_lObjectDetails, 0);
	   rotation l_rLaunchAngle = llRotBetween (<1., 0., 0.>, l_vTargetPos - llGetRootPosition ());
	   
	   llRezObject ("killer",
					llGetRootPosition () + (k_iRezOffset * l_rLaunchAngle),
					k_vDamagePrimVelocity * l_rLaunchAngle,
					ZERO_ROTATION,
					k_iDamageAmount);
	 }
   }
   
   object_rez (key in_kObjectKey) {
	 llSay ((integer)("0x" + llGetSubString ((string)in_kObjectKey, 0, 7)), llList2String(g_kVictim,0));
	 g_kVictim = llDeleteSubList (g_kVictim, 0, 0);
   }
 }
